package com.shangcheng.dubbo.api;

import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.convert.Convert;
import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.shangcheng.dubbo.mappers.PmsMemberPriceMapper;
import com.shangcheng.model.domain.PmsMemberPrice;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

@DubboService
public class PmsMemberPriceApiImpl implements PmsMemberPriceApi {
    @Autowired
    private PmsMemberPriceMapper memberPriceMapper;

    @Override
    public void save(List<PmsMemberPrice> memberPriceList, Long id) {
        if (ObjectUtil.isNotEmpty(memberPriceList)) {
            for (PmsMemberPrice pmsMemberPrice : memberPriceList) {
                pmsMemberPrice.setProductId(id);
                memberPriceMapper.insert(pmsMemberPrice);
            }
        }
    }

    @Override
    public List<PmsMemberPrice> findByProductId(Integer id) {
        return memberPriceMapper.selectList(new LambdaQueryWrapper<PmsMemberPrice>().eq(PmsMemberPrice::getProductId, id));
    }

    @Override
    public void updateById(List<PmsMemberPrice> memberPriceList, Integer id) {
        memberPriceMapper.delete(new LambdaQueryWrapper<PmsMemberPrice>().eq(PmsMemberPrice::getProductId, id));
        this.save(memberPriceList, Convert.toLong(id));
    }
}
